package tryCatchTest;

/**
 * 异常链测试
 * 如果catch处理了一个异常，又抛出来一个异常，这时候可能需要将异常连接起来
 * @author lcx
 *
 */
public class ExceptionConnectTest {
	
	public static void method1() throws Exception
	{
		System.out.println("进入method1()");
		throw new Exception("method1()出现异常");
	}

	public static void method2() throws Exception
	{
		System.out.println("进入method2()");
		try
		{
		method1();
		}
		catch(Exception ex)
		{
			System.out.println("method2()处理异常");
			Exception ex1=new Exception("method2()又抛出一个异常");
			ex1.initCause(ex);
			throw ex1;
		}
	}

	public static void method3()
	{
		System.out.println("进入method3()");
		try
		{
			method2();
		}
		catch(Exception ex)
		{
			System.out.println("method3()处理异常");
			ex.printStackTrace();
		}
	}


	public static void main(String[] args) {
		method3();
	}
}
